package org.xjtu.weteam.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.xjtu.weteam.model.domain.User;

/**
 * BaseMapper 通常会提供一些基本的 CRUD，无需再重复写
 * @author Kevin
 */

@Mapper
public interface UserMapper extends BaseMapper<User> {

//    @Select("SELECT * FROM User WHERE user_id = #{id}")
//    User selectById(Integer id);

    @Select("SELECT * FROM user WHERE open_id = #{openid}")
    User findByOpenid(String openid);

    @Insert("INSERT INTO user (open_id, nickname) VALUES (#{openId}, #{nickname})")
    int insertByOpenId(User user);

    boolean getUserId(@Param("name") String name);

    // 根据 user_id 更新 imagePath 和 nickname
    @Update("UPDATE user SET image_path = #{imagePath}, nickname = #{nickname} WHERE user_id = #{userId}")
    int updateUserById(@Param("userId") Integer userId, @Param("imagePath") String imagePath, @Param("nickname") String nickname);

    @Update("UPDATE user SET nickname = #{nickname} WHERE user_id = #{userId}")
    int updateNameById(@Param("userId") Integer userId, @Param("nickname") String nickname);

}
